package top.sxlai.controller;

import top.sxlai.entity.DTO.FileFolderDTO;
import top.sxlai.entity.aggregation.AggregationFileFolder;
import top.sxlai.service.IFileFolderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Map;

/**
 * @author : sxl
 * @date : 2024/4/16 21:36
 * @Version: 1.0
 */
@RestController
public class FileAndFolderController {
    @Autowired
    private IFileFolderService iFileFolderService;
    @PostMapping("/deleteFiles")
    public ResponseEntity<Map<String,String>> deleteFiles(@RequestBody AggregationFileFolder aggregationFileFolder) throws IOException {
        if("delete".equals(aggregationFileFolder.getDeleteWay())){ //进行删除操作
            return iFileFolderService.deleteFiles(aggregationFileFolder);
        }else { //进行回收操作
            return iFileFolderService.recycleFiles(aggregationFileFolder);
        }
    }
    @PostMapping("/moveFilePath")
    public ResponseEntity<Map<String,String>> moveFilePath(@RequestBody AggregationFileFolder aggregationFileFolder) throws IOException {

        return iFileFolderService.moveFilePath(aggregationFileFolder);
    }
    @PostMapping("/rename")
    public ResponseEntity<Map<String,String>>rename(@RequestBody FileFolderDTO fileFolderDTO) throws IOException {
        return iFileFolderService.rename(fileFolderDTO);
    }
}
